package com.aube.rvi.net;

import java.io.UnsupportedEncodingException;

/**
 * Created by huyaonan on 16/5/9.
 */
public class FileRequest extends Request<String> {

    private String fileTitle="";

    public FileRequest(String url, ResponseListener<String> listener) {
        super(Request.Method.GET, url, listener);
        fileTitle = url.hashCode() + "";
        setShouldCache(false);
    }

    public void setFileTitle(String title) {
        this.fileTitle = title;
    }

    public String getFileTitle() {
        return fileTitle;
    }

    @Override
    public void deliverResponse(String response) {
        if(mListener != null)
            mListener.onResponse(response);
    }

    @Override
    protected Response<String> parseNetworkResponse(NetworkResponse response) {
        String parsed;
        try {
            parsed = new String(response.data, HttpHeaderParser.parseCharset(response.headers));
        } catch (UnsupportedEncodingException e) {
            parsed = new String(response.data);
        }
        return Response.success(parsed, HttpHeaderParser.parseCacheHeaders(response));
    }

}
